package com.example.dao;

import com.example.domain.t_article;
import com.example.domain.t_statistic;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface statisticMapper {
    //新增文章评论表,即创建文章即创建表
    @Insert("insert into t_statistic values(null,#{id},0,0)")
    public boolean addStatistic(t_article article);

    //获取文章表
    @Select("select * from t_statistic where article_id=#{article_id}")
    public t_statistic getStatisticById(int article_id);

    //更新表
    @Update("update t_statistic set hits=#{hits},comments_num=#{comments_num} " +
            " where article_id=#{article_id}")
    public boolean updateStatisticByArticleId(t_statistic statistic);


    //删除表
    @Delete("delete from t_statistic where article_id=#{article_id}")
    public boolean deleteStatisticByArticleId(int article_id);

    //按照热度排序（分页）
    @Select("select * from t_statistic where hits != 0 " +
            "order by hits DESC,comments_num DESC")
    public List<t_statistic> getStatisticSort();
    @Select("select * from t_statistic where hits != 0 " +
            "order by hits DESC,comments_num DESC " +
            "limit #{count},#{size}")
    public List<t_statistic> getStatisticSortPage(int count,int size);

    //统计文章热度信息
    @Select("select sum(hits) from t_statistic")
    public int getSumHits();

    //统计总评论量
    @Select("select sum(comments_num) from t_statistic")
    public int getSumComment();
}
